var Db = require('mongodb').Db;
var BSON = require('mongodb').BSONPure;
var Server = require('mongodb').Server;

var dbApi = {};

dbApi.open = function (dbHost, dbPort, dbName, fn) {
	dbApi.server = new Server(dbHost, dbPort, {
        auto_reconnect: true
    }, {safe:true});
    dbApi.db = new Db(dbName, dbApi.server);
    dbApi.db.open(function (e) {
        if (e) {
        	return
        } else {
            if (fn) {
                fn();
            }
        }
    });

    dbApi.user = dbApi.db.collection('user');
};

module.exports = dbApi;